import Vue from 'vue';
import Vuex from 'vuex';
import api from '@/api';
// 用来调试vuex中的bug
import createLogger from 'vuex/dist/logger';

// 获取node环境变量
//   npm run serve --> development
//   npm run build --> production
const debug = process.env.NODE_ENV !== "production";

Vue.use(Vuex);
export default new Vuex.Store({
    state: {
        homeDate: [],
    },
    mutations: {
        queryHomeData(state, data) {
            state.homeDate = data;
        }
    },
    actions: {
        async queryHomeDataAsync({ commit }) {
            let data = await api.homeDate();
            commit('queryHomeData', data)
        }
    },
    // 保证只有开发环境使用logger
    plugins: debug ? [createLogger()] : [],
});